package com.zsr.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsr.example.entity.SysLog;
import com.zsr.example.mapper.SysLogMapper;
import com.zsr.example.service.SysLogService;
import com.zsr.example.vo.SysLogReq;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsr
 * @since 2021-12-16
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public void pageQueryView(Page<SysLog> page, SysLogReq sysLogReq) {
        //MP 构建条件
        QueryWrapper<SysLog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        String method = sysLogReq.getMethod();
        Integer level = sysLogReq.getLevel();
        String requestUrl = sysLogReq.getRequestUrl();
        String userId = sysLogReq.getUserId();
        String begin = sysLogReq.getBegin();
        String end = sysLogReq.getEnd();
        if (!StringUtils.isEmpty(method)) wrapper.like("method", method);
        if (!StringUtils.isEmpty(level)) wrapper.eq("level", level);//等于
        if (!StringUtils.isEmpty(requestUrl)) wrapper.like("request_url", requestUrl);//大于
        if (!StringUtils.isEmpty(userId)) wrapper.eq("user_id", userId);//小于
        if (!StringUtils.isEmpty(begin)) wrapper.ge("create_time", begin);//大于
        if (!StringUtils.isEmpty(end)) wrapper.le("create_time", end);//小于


        baseMapper.selectPage(page, wrapper);
    }
}
